package com.jic.data.controller;

import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
import com.jic.data.constant.consist.ResponseCode;
import com.jic.data.model.entity.MonOneMoreGuestBaseCategory;
import com.jic.data.model.entity.MonOneMoreGuestDetailCategory;
import com.jic.data.model.entity.MonProductSaleAmount;
import com.jic.data.model.vo.request.MonOneMoreGuestBaseCategoryRequest;
import com.jic.data.model.vo.request.MonOneMoreGuestDetailCategoryRequest;
import com.jic.data.model.vo.request.MonProductSaleAmountRequest;
import com.jic.data.model.vo.response.*;
import com.jic.data.service.MonOneMoreGuestBaseCategoryService;
import com.jic.data.service.MonOneMoreGuestDetailCategoryService;
import com.jic.data.service.MonProductSaleAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: 建投数据科技(山东)有限公司
 * @date: 2020-05-09 17:25:18
 */
@RestController
@Slf4j
@RequestMapping("/monProductSaleAmount")
@Api(tags = " [商品销售-品类-月度")
public class MonProductSaleAmountCategoryController {
    @Autowired
    private MonProductSaleAmountService service;

    @Autowired
    private MonOneMoreGuestBaseCategoryService monOneMoreGuestBaseCategoryService;

    @Autowired
    private MonOneMoreGuestDetailCategoryService monOneMoreGuestDetailCategoryService;

    @Autowired
    private MonProductSaleAmountService monProductSaleAmountService;

    // TODO 修改完成
    @PostMapping("/list/prdu/amo/unitprice")
    @ApiOperation(value = "月度商品销售额&件单价")
    @ResponseBody
    public RestResult<HistogramChartResponse> monProductAmountUnitPrice(@RequestBody MonProductSaleAmountRequest request){
        MonProductSaleAmount monProductSaleAmount = new MonProductSaleAmount();
        BeanUtils.copyProperties(request, monProductSaleAmount);
        HistogramChartResponse response = monProductSaleAmountService.listAllRecord(monProductSaleAmount);
        return RestResult.success(response);
    }


    // TODO 修改完成
    @PostMapping("/list/guest/quantity")
    @ApiOperation(value = "一次客回购客数量")
    @ResponseBody
    public RestResult<HistogramChartResponse> listOneMoreGuestQuantity(@RequestBody MonOneMoreGuestBaseCategoryRequest request) throws Throwable {
        MonOneMoreGuestBaseCategory monProductSaleAmount = new MonOneMoreGuestBaseCategory();
        BeanUtils.copyProperties(request, monProductSaleAmount);
        HistogramChartResponse response = monOneMoreGuestBaseCategoryService.selectOneMoreGuestQuantity(monProductSaleAmount);
        return RestResult.success(response);
    }


    // TODO 修改完成
    @PostMapping("/query/guest/amount")
    @ApiOperation(value = "一次客回购客销售占比")
    @ResponseBody
    public RestResult<List<PieChartResponse>> queryOneMoreGuestAmount(@RequestBody MonOneMoreGuestBaseCategoryRequest request) throws Throwable {
        MonOneMoreGuestBaseCategory monProductSaleAmount = new MonOneMoreGuestBaseCategory();
        BeanUtils.copyProperties(request, monProductSaleAmount);
        List<PieChartResponse> list = monOneMoreGuestBaseCategoryService.selectOneMoreGuestAmount(monProductSaleAmount);
        return RestResult.success(list);
    }


    // TODO 修改完成
    /**
     * 月度品类销售明细
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/mon/category/guestDetail")
    @ApiOperation(value = "月度品类销售明细")
    @ResponseBody
    public RestResult<List<MonOneMoreGuestDetailCategory>> listMonOneMoreGuestDetailCategoryAllRecord(@RequestBody MonOneMoreGuestDetailCategoryRequest request) throws Throwable {
        MonOneMoreGuestDetailCategory monOneMoreGuestDetailCategory = new MonOneMoreGuestDetailCategory();
        BeanUtils.copyProperties(request, monOneMoreGuestDetailCategory);
        List<MonOneMoreGuestDetailCategory>  list = monOneMoreGuestDetailCategoryService.listAllRecord(monOneMoreGuestDetailCategory);
        return RestResult.success(list);
    }

    // TODO 修改完成
    /**
     * 月度一次客回购客对比
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/mon/oneMoreInfo")
    @ApiOperation(value = "月度一次客回购客对比")
    @ResponseBody
    public RestResult<List<MonOneMoreGuestDetailCategoryResponse>> listOneMoreInfoAllRecord(@RequestBody MonOneMoreGuestDetailCategoryRequest request) throws Throwable {
        MonOneMoreGuestDetailCategory monOneMoreGuestDetailCategory = new MonOneMoreGuestDetailCategory();
        BeanUtils.copyProperties(request, monOneMoreGuestDetailCategory);
        List<MonOneMoreGuestDetailCategoryResponse> responseList = monOneMoreGuestDetailCategoryService.selectOneMoreInfo(monOneMoreGuestDetailCategory);

        return RestResult.success(responseList);
    }

}

